package com.yanchangapp.ui.fragment.home;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.yanchangapp.TestActivity;
import com.yanchangapp.ui.activity._n_manage.DailyPlanActivity;
import com.yanchangapp.ui.activity._n_manage.LinkWorkItemActivity;
import com.yanchangapp.ui.activity._n_manage.WorkItemActivity;
import com.zxl.baselib.ui.base.BaseFragment;
import com.yanchangapp.R;
import com.yanchangapp.adapter.WorkComposeAdapter;
import com.yanchangapp.model.bean.ComposeMenuIcons;
import com.yanchangapp.ui.activity.base.MainActivity;
import com.yanchangapp.ui.activity.msg.MessageActivity;
import com.yanchangapp.ui.presenter.WorkFgPresenter;
import com.yanchangapp.ui.view.WorkFgView;
import com.zxl.baselib.util.ui.UIUtils;
import com.zxl.baselib.widget.TipDialog;

import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;

public class WorkFragment extends BaseFragment<WorkFgView, WorkFgPresenter> implements WorkFgView {

    @BindView(R.id.ivToolbarNavigation)
    ImageView ivToolbarNavigation;
    @BindView(R.id.vToolbarDivision)
    View vToolbarDivision;
    @BindView(R.id.tvToolbarTitle)
    TextView tvToolbarTitle;
    @BindView(R.id.ivRightOne)
    ImageView ivRightOne;
    @BindView(R.id.workRecycleView)
    RecyclerView workRecycleView;
    private WorkComposeAdapter mWorkComposeAdapter;
    private List<ComposeMenuIcons> mComposeMenuIconsList = new ArrayList<>();

    private int currentIndex = -1;

    @Override
    public void init() {

    }

    @Override
    protected int provideContentViewId() {
        return R.layout.fragment_home_work;
    }

    @Override
    protected WorkFgPresenter createPresenter() {
        return new WorkFgPresenter((MainActivity)getActivity());
    }

    @Override
    public void initView(View rootView) {
        ivToolbarNavigation.setVisibility(View.INVISIBLE);
        tvToolbarTitle.setText("我的工作");
        ivRightOne.setVisibility(View.VISIBLE);
        ivRightOne.setImageResource(R.mipmap.ic_notification);
        initWorkAdapter();
        loadWorkData();
        setConListener();
    }

    private void setConListener() {
        ivRightOne.setOnClickListener(v -> MessageActivity.show(getActivity()));
    }

    private void loadWorkData() {
        mPresenter.fetchList();
    }

    private void initWorkAdapter() {
        workRecycleView.setLayoutManager(new LinearLayoutManager(getContext(),LinearLayoutManager.VERTICAL,false));
        mWorkComposeAdapter = new WorkComposeAdapter(R.layout.item_compose_rv,mComposeMenuIconsList,getActivity());
        workRecycleView.setAdapter(mWorkComposeAdapter);
    }

    @Override
    public void initData() {

    }

    @Override
    public void initListener() {
        // tvToolbarTitle.setOnClickListener(v -> LinkWorkItemActivity.show(getActivity()));
    }

    @Override
    public void queryWorkListSuccess(List<ComposeMenuIcons> menuIcons) {
        mComposeMenuIconsList.clear();
        mComposeMenuIconsList.addAll(menuIcons);
        mWorkComposeAdapter.notifyDataSetChanged();
    }

    @Override
    public void queryWorkListFailure(String msg) {
        UIUtils.showToast(msg);
    }
}
